/**
 * @filename:CarServiceImpl 2019-01-17 14:56:43
 * @project skz  V1.3.3
 * Copyright(c) 2018 Liu,Wenzhao Co. Ltd. 
 * All right reserved. 
 */
package com.bingsum.service;

import com.bingsum.annotation.Api;
import com.bingsum.mapper.CarMapper;
import com.bingsum.mapper.OdometerMapper;
import com.bingsum.model.Car;
import com.bingsum.model.Odometer;
import com.bingsum.util.ApiUtil;
import com.bingsum.util.ParaData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("odometerService")
@Transactional(readOnly = true)
public class OdometerService {

    @Autowired
    private OdometerMapper odometerMapper;

    @Api
    public Object getOdometerInfoList(ParaData pd) {
        Page<?> page = PageHelper.startPage(pd.getInteger("currentPage"), 20);
        odometerMapper.getOdometerInfoList(pd);
        return ApiUtil.returnObject(pd, page);
    }

    @Api
    public ParaData getOdometerInfo(ParaData pd) {
        return odometerMapper.getOdometerInfo(pd);
    }

    @Api
    @Transactional(readOnly = false)
    public Object newOdometerInfo(ParaData pd) {
        Odometer odometer = pd.toBean(Odometer.class);
        this.odometerMapper.insert(odometer);
        return ApiUtil.returnOK(pd,odometer);
    }

    @Api
    @Transactional(readOnly = false)
    public Object delOdometer(ParaData pd) {
        Odometer odometer = pd.toBean(Odometer.class);
        this.odometerMapper.updateByPrimaryKeySelective(odometer);
        return ApiUtil.returnOK(pd,odometer);
    }


}